#!/bin/bash

# 获取脚本所在目录及其名称
script_path=$(readlink -f "$0")
dir_path=$(dirname "$script_path")
dir_name=$(basename "$dir_path")
echo "Directory name: $dir_name"

# 设置变量
GITEE_TOKEN="00fe76a872ca795d8b6107aec51c16a4"
PRIVATE=true # 设置为 true 以创建私有仓库，false 以创建公有仓库

# 创建仓库
response=$(curl -s -o response.json -w "%{http_code}" -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: token ${GITEE_TOKEN}" \
  -d '{"name":"'"${dir_name}"'","private":'"${PRIVATE}"'}' \
  https://gitee.com/api/v5/user/repos)

# 检查HTTP响应代码
if [ "$response" -eq 201 ]; then
  echo "仓库创建成功！"
else
  echo "创建仓库失败，HTTP响应代码: $response"
  cat response.json
fi

# 清理临时文件
rm -f response.json

git add . && git commit -m "first commit" && git push origin main